/*
 * MyMethod.cpp
 *
 *  Created on: Aug 10, 2010
 *      Author: sdaniele
 */

#include "MyMethod.h"
#include "flops_job.h"
#include "tbb/mutex.h"

typedef ::tbb::mutex mutex_t;
mutex_t print_mutex;


MyMethod::MyMethod(::pilot::scheduler* s, size_t logflops, ::std::string name, ::std::string label, size_t max_depth, size_t counter)
	:m_sched(s), m_logflops(logflops), m_name(name), m_label(label),m_max_depth(max_depth), m_counter(counter)
{}

MyMethod::~MyMethod() {}


void MyMethod::operator()(){
	::pilot::flops_job(m_logflops,m_label);

	report();
	++m_counter;
	if(m_counter<m_max_depth)
		m_sched->spawn(this);
}

void MyMethod::report() const{
	mutex_t::scoped_lock lock(print_mutex);
	::std::cout << m_counter << " [" << m_name << "] reporting 2^" << m_logflops << " flops done, elapsed " << m_sched->seconds_elapsed() << " sec." << ::std::endl;
}

